package com.management.controller;


import com.baomidou.mybatisplus.extension.api.R;
import com.management.controller.form.ChangeRoleNameForm;
import com.management.controller.form.RolePageForm;
import com.management.service.RoleService;
import com.management.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 龙世超
 * @since 2022-03-23
 */
@Api(tags = "角色相关")
@RestController
@RequestMapping("/role")
public class RoleController {
    @Resource
    private RoleService roleService;

    /**
     * 分页查询所有角色
     * @param rolePageForm 获取参数
     * @return
     */
    @ApiOperation("分页查询所有角色")
    @PostMapping("getAllRoleByPage")
    public Result getAllRoleByPage(@RequestBody RolePageForm rolePageForm){
       Result result= roleService.findRoleByPage(rolePageForm);
       return result;
    }
    @GetMapping("getAllRole")
    public Result getAllRole(){
       Result result= roleService.findAllRole();
       return result;
    }

    /**
     * 修改角色状态
     * @param roleNum 角色ID
     * @return
     */
    @ApiOperation("修改角色状态")
    @GetMapping("closeRole")
    public Result closeRole(Integer roleNum){
       Result result= roleService.closeRole(roleNum);
       return result;
    }

    /**
     * 修改角色信息之前检查角色状态
     * @param roleNum 角色ID
     * @return
     */
    @ApiOperation("修改角色信息之前检查角色状态")
    @GetMapping("checkRoleState")
    public Result checkRoleState(Integer roleNum){
        Result result=roleService.checkRoleState(roleNum);
        return result;
    }

    /**
     * 修改角色状态
     * @param changeRoleNameForm 参数
     * @return
     */
    @ApiOperation("修改角色状态")
    @GetMapping("changeRoleName")
    public Result changeRoleName( ChangeRoleNameForm changeRoleNameForm){
       Result result= roleService.changeRoleName(changeRoleNameForm);
       return result;
    }

    /**
     * 根据ID删除角色
     * @param roleNum 角色ID
     * @return
     */
    @ApiOperation("根据ID删除角色")
    @GetMapping("delRole")
    public Result delRole(Integer roleNum){
       Result result= roleService.delRole(roleNum);
       return result;
    }
}

